package com.sunlei.seata.bussiness.service;

import com.sunlei.seata.bussiness.client.OrderServiceClient;
import com.sunlei.seata.bussiness.client.AccountServiceClient;
import com.sunlei.seata.bussiness.client.entity.Order;
import io.seata.spring.annotation.GlobalTransactional;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 业务逻辑
 */
@Service
public class BussinessService {
    @Resource
    private AccountServiceClient accountServiceClient;
    @Resource
    private OrderServiceClient orderServiceClient;



    @GlobalTransactional(name = "fsp-sale" , timeoutMills = 20000000 , rollbackFor = Exception.class)
    public Order sale(String goodsCode , Integer quantity ,String username ,Integer points, Float amount ){
        accountServiceClient.increase(username, points);
        Order order = orderServiceClient.create(goodsCode, quantity, username, points, amount);
        try {
            Thread.sleep(6000);
        } catch (InterruptedException e) {
            e.printStackTrace();
        }
        return order;
    }
}
